package pool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/*
JDK自带线程池
Executors.newCachedThreadPool 创建一个默认的线程池
Executors.newFixedThreadPool 创建一个指定最多数量的线程池
 */
public class Demo1 {
    public static void main(String[] args) {
        //获取线程池对象
        ExecutorService pool = Executors.newFixedThreadPool(10);
        //提交线程任务
        for (int i = 0; i < 100; i++) {
            pool.submit(new Runnable() {
                @Override
                public void run() {
                    System.out.println(Thread.currentThread().getName()+"提交了线程任务");
                }
            });
        }

        //关闭线程池
        pool.shutdown();
    }
}
